<template>
	<view>
		<!-- 支付表单 -->
		<view style="margin-top: 20rpx;padding: 20rpx;background-color: white;">
			<u-form :model="form" ref="uForm" label-width="200">
				<u-form-item label="附件名称" prop="doc_name"><u-input v-model="form.doc_name" /></u-form-item>
				<u-form-item label="上传附件" prop="doc_src">
					<u-upload ref="uUpload" :auto-upload="false" :show-progress="true"
						:form-data="{path:'/static/file/order_doc/'}" :multiple="true">
					</u-upload>
				</u-form-item>
				<view style="width: 100%;">
					<u-button @click="submit" type="primary">添加</u-button>
				</view>
			</u-form>
		</view>
		<u-toast ref="uToast"></u-toast>
		<!-- <u-avatar src="http://tmp/ExThmpgDoq9dd60ec45b54a0ac551cea6964878ba556.jpg"></u-avatar> -->
	</view>
</template>

<script>
	import {
		data
	} from 'uview-ui/libs/mixin/mixin';
	import cos from '../../utils/cos';
	// const COS = require('cos-js-sdk-v5');
	export default {
		data() {
			return {
				orders:null,
				pay_type: '',
				showSelectChannel: false,
				uploadList: [],
				host: '',
				data: {},
				form: {
					doc_name: '',
					doc_src: ''
				},
				rules: {
					doc_name: [{
						required: true,
						message: '请输入退还原因',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		onLoad(options) {
			this.orders = JSON.parse(decodeURIComponent(options.data));
			this.host = this.$http.host;
		},
		mounted() {

		},
		methods: {
			submit() {
				var that = this;
				var list = this.$refs.uUpload.lists;
				var dir = '/static/file/order_doc/';
				this.$refs.uForm.validate(valid => {
					if (valid) {
						cos.uploadFiles(list, dir, (data) => {
							console.log(data);
							var record_img = data.files.map(item => item.options.Key);
							this.form.doc_src = record_img.toString();
							this.form.orders_id = that.orders.orders_id;
							that.$http.post('/ordersDoc/insert', this.form, (res) => {
								if (res.data.success) {
									console.log(that.$refs.uToast);
									that.$refs.uToast.show({
										title: '添加成功',
										type: "success"
									});
									uni.$emit("getOrdersInfo", that.data);
									uni.navigateBack();
								} else {
									that.$refs.myModal.show('登录失败', res.data.result.message);
								}
							});
						});
					} else {
						console.log('验证失败');
					}
				});
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style>

</style>